/*      $Id: mod_java.h 983 2009-09-01 02:45:42Z phrakt $    */
/*
 * Copyright (c) 2007 Jean-Francois Brousseau <phrakt@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _MOD_JAVA_MOD_JAVA_H_
#define _MOD_JAVA_MOD_JAVA_H_

#include <sys/types.h>

#include <jni.h>

#include <canopy/log.h>


/* configuration directive to load Java handlers */
#define MOD_JAVA_CONF_DIR	"javaload"



#define MOD_JAVA_PACKAGE	"ca.terraquati.canopy"

#define MOD_JAVA_REQUEST_CLASS	"ca.terraquati.canopy.http.native.NativeHTTPRequest"
#define MOD_JAVA_RESPONSE_CLASS	"ca.terraquati.canopy.http.native.NativeHTTPResponse"
#define MOD_JAVA_SOCKET_CLASS	"ca.terraquati.canopy.http.native.NativeHTTPSocket"



/* ghetto */
extern cnp_log_t *httpd_logchan;
#define canopy_log(p, ...)      cnp_log(httpd_logchan, p, __VA_ARGS__)


int          mod_java_init          (void);
void         mod_java_cleanup       (void);
int          mod_java_jvminit       (void);
int          mod_java_jvmstop       (void);

jclass       mod_java_getclass  (JNIEnv *, const char *, int);

void*        mod_java_getpeer   (JNIEnv *, jobject, const char *);
int          mod_java_setpeer   (JNIEnv *, jobject, const char *, const void *);

int          mod_java_loadhdlr  (const char *);

/* C <-> Java conversion functions */
jint         mod_java_int_ctoj     (JNIEnv *, int);
int          mod_java_int_jtoc     (JNIEnv *, jint);
jstring      mod_java_string_ctoj  (JNIEnv *, const char *);
ssize_t      mod_java_string_jtoc  (JNIEnv *, jstring, char *, size_t);

const char*  mod_java_jnierr    (jint);


/* initialization for classes with native code */
int          mod_java_load_Canopy         (JNIEnv *);
int          mod_java_load_HTTPMessage    (JNIEnv *);
int          mod_java_load_HTTPSocketImpl (JNIEnv *);


#endif	/* _MOD_JAVA_MOD_JAVA_H_ */
